package com.fyzk.activity.zhifu.zc;

import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.fyzk.bean.ZCGameQueueItem;
import com.tyjc.lottery.R;
import com.fyzk.utils.TextStyleUtil;

import java.util.List;

public class ZhiFu_BQC_Adapter extends ZhiFu_ZC_Adapter{


	public ZhiFu_BQC_Adapter(Context context, List<ZCGameQueueItem> infors) {
		super(context, infors);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ZCGameQueueItem data = infors.get(position);
		final ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.adapter_bqc_pay, null);

			holder.num_tv =  (TextView) convertView.findViewById(R.id.bqc_pay_item_num);
			holder.home_tv =  (TextView) convertView.findViewById(R.id.zc_bqc_home);
			holder.away_tv =  (TextView) convertView.findViewById(R.id.zc_bqc_away);
			holder.ban_sheng_check = (CheckBox) convertView.findViewById(R.id.zc_bqc_ban_sheng);
			holder.ban_ping_check = (CheckBox) convertView.findViewById(R.id.zc_bqc_ban_ping);
			holder.ban_fu_check = (CheckBox) convertView.findViewById(R.id.zc_bqc_ban_fu);
			holder.quan_sheng_check = (CheckBox) convertView.findViewById(R.id.zc_bqc_quan_sheng);
			holder.quan_ping_check = (CheckBox) convertView.findViewById(R.id.zc_bqc_quan_ping);
			holder.quan_fu_check = (CheckBox) convertView.findViewById(R.id.zc_bqc_quan_fu);

			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}

		holder.num_tv.setText(""+(position+1));

		holder.home_tv.setText(data.getHomeTeam());
		holder.away_tv.setText(data.getAwayTeam());

		holder.ban_sheng_check.setChecked(data.isBanSheng);
		holder.ban_ping_check.setChecked(data.isBanPing);
		holder.ban_fu_check.setChecked(data.isBanFu);
		holder.quan_sheng_check.setChecked(data.isQuanSheng);
		holder.quan_ping_check.setChecked(data.isQuanPing);
		holder.quan_fu_check.setChecked(data.isQuanFu);

		holder.ban_sheng_check.setText("");
		holder.ban_ping_check.setText("");
		holder.ban_fu_check.setText("");
		holder.quan_sheng_check.setText("");
		holder.quan_ping_check.setText("");
		holder.quan_fu_check.setText("");

		SpannableString spanString = TextStyleUtil.fontSizeSpan(new SpannableString("3 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.ban_sheng_check.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+data.getHalf_3()+")"), 12);
		holder.ban_sheng_check.append(spanString);

		spanString = TextStyleUtil.fontSizeSpan(new SpannableString("1 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.ban_ping_check.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+data.getHalf_1()+")"), 12);
		holder.ban_ping_check.append(spanString);

		spanString = TextStyleUtil.fontSizeSpan(new SpannableString("0 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.ban_fu_check.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+data.getHalf_0()+")"), 12);
		holder.ban_fu_check.append(spanString);


		spanString = TextStyleUtil.fontSizeSpan(new SpannableString("3 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.quan_sheng_check.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+data.getFull_3()+")"), 12);
		holder.quan_sheng_check.append(spanString);

		spanString = TextStyleUtil.fontSizeSpan(new SpannableString("1 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.quan_ping_check.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+data.getFull_1()+")"), 12);
		holder.quan_ping_check.append(spanString);

		spanString = TextStyleUtil.fontSizeSpan(new SpannableString("0 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.quan_fu_check.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+data.getFull_0()+")"), 12);
		holder.quan_fu_check.append(spanString);


		holder.ban_sheng_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isBanSheng = ! data.isBanSheng;
				if (data.isBanSheng) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				tongJi();
			}
		});

		holder.ban_ping_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isBanPing = ! data.isBanPing;
				if (data.isBanPing) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				tongJi();
			}
		});

		holder.ban_fu_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isBanFu = ! data.isBanFu;
				if (data.isBanFu) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				tongJi();
			}
		});


		holder.quan_sheng_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isQuanSheng = ! data.isQuanSheng;
				if (data.isQuanSheng) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}
				tongJi();
			}
		});

		holder.quan_ping_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isQuanPing = ! data.isQuanPing;
				if (data.isQuanPing) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}
				tongJi();
			}
		});

		holder.quan_fu_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isQuanFu = ! data.isQuanFu;
				if (data.isQuanFu) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}
				tongJi();
			}
		});

//		if (position == jcInfors.size()) {
//			holder.bg_center.setVisibility(View.GONE);
//			holder.bg_top.setVisibility(View.GONE);
//		} else {
//			Globle.setHW(holder.bg_top, 1080, 11, context);
//			ZCGameQueueItem info = jcInfors.get(position);
//			holder.fangshi.setText("[" + ConstantsDJ.wcode(info.wcodeID) + "]");
//			holder.tv_betNum.setText(Html.fromHtml(info.showZhuMa));
//			holder.zhu.setText(info.zhuShu + "注,");
//			holder.money.setText("共 " + info.zhuShu * 2 + " 米");
//			holder.bg_center.setOnClickListener(new OnClickListener() {
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if (listener != null) {
//						listener.onClickChange(position);
//					}
//				}
//			});
//			holder.delete.setOnClickListener(new OnClickListener() {
//
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if (listener != null) {
//						listener.onClickDelete(position);
//					}
//				}
//			});
//		}
		
		
		
		return convertView;
	}

	protected void tongJi(){
		if (listener != null) {
			listener.onClickBall();
		}
	}

	private SpannableString setTextStyle(String text){
		SpannableString spanString = TextStyleUtil.fontSizeSpan(new SpannableString(text), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD_ITALIC);
		return spanString;
	}

	class ViewHolder {
		TextView num_tv;
		TextView home_tv;
		TextView away_tv;
		CheckBox ban_sheng_check;
		CheckBox ban_ping_check;
		CheckBox ban_fu_check;
		CheckBox quan_sheng_check;
		CheckBox quan_ping_check;
		CheckBox quan_fu_check;
	}

}
